// 引入sequelize和相关的数据库驱动
const { Sequelize } = require('sequelize');

// 数据库配置信息
const config = {
  host: '127.0.0.1',
  dialect: 'mysql',
  database: 'lyh_uniapp_db',
  username: 'root',
  password: '20010515wei'
}

// 创建sequelize实例
const sequelize = new Sequelize(config.database, config.username, config.password, {
  host: config.host,
  dialect: config.dialect
})

// 同步数据库模型
const connectDb = async () => {
  try {
    await sequelize.authenticate()
    console.log('数据库连接成功');

  } catch (error) {
    console.log('数据库连接失败', error);
  }
}

connectDb()

module.exports = sequelize